package gui.components.map.objects;

import gui.components.map.engine.RenderQueue;
import gui.components.map.engine.RenderQueueType;

import java.awt.Color;
import java.awt.Font;
import java.awt.geom.Ellipse2D;

import javax.swing.JPanel;

public class objRadialGrid extends objGrid{

	private int _aantal;
	private double _straal;
	private double _afstand;
	private Ellipse2D.Double _radian;
	private Color _textcolor;
	
	private RenderQueue _renderqueue_text;
	private RenderQueue _renderqueue_grid;

	
	public objRadialGrid()
	{
		// Run superclass
		super();
		_type = GridType.Radial;
	}
	
	public void GenerateGrid(JPanel _panel)
	{
		_renderqueue_text = new RenderQueue();
		_renderqueue_grid = new RenderQueue();
		
		_renderqueue_text.SetType(RenderQueueType.TEXT);
		_renderqueue_grid.SetType(RenderQueueType.GRIDRADIAL);

		_renderqueue.Add(_renderqueue_text);
		_renderqueue.Add(_renderqueue_grid);
		
		
		_type = GridType.Radial;
		
		_straal = GetSmallest() / 2;
		_afstand = GetSmallest() / _aantal;
		GenerateEllipse();
		GenerateLabels();
	}
	
	private void GenerateEllipse()
	{
		for(int i = 1; i <= _aantal; i++)
		{
			_radian = new Ellipse2D.Double(_pnl.getWidth() / 2 - _straal, _pnl.getHeight() / 2 - _straal,(_straal * 2), _straal *2);
			_straal -= (GetSmallest() / 2) / _aantal;
			
			// Add radian grid to queue
			cShape _cshape = new cShape();
			_cshape.SetColor(this.GetColor());
			_cshape.SetShape(_radian);
			
			_renderqueue_grid.Add(_cshape);
			
		}
	}
	private void GenerateLabels()
	{
		for(int i = 1; i <= _aantal; i++)
		{
			cText _text = new cText();
			_text.setFont(new Font("Arial", Font.BOLD, 10));
			_text.setColor(GetTextColor());
			_text.setText(i*(75/(_aantal - 1)) + " NM");
			_text.setX((_pnl.getWidth()/2) - (_aantal) + (i * _afstand/2));
			_text.setY((_pnl.getHeight()/2 - 15) + 5);

			_renderqueue_text.Add(_text);
		}
		
	}
	
	private double GetSmallest()
	{
		double _tmp = _pnl.getHeight() > _pnl.getWidth() ? _pnl.getHeight() : _pnl.getWidth();
		_tmp = (_tmp / _aantal) * 2;
		
		return _pnl.getHeight() > _pnl.getWidth() ? _pnl.getHeight() + _tmp : _pnl.getWidth() + _tmp;
	}
	
	public void SetTextColor(Color _c)
	{
		_textcolor = _c;
	}
	
	public Color GetTextColor()
	{
		return _textcolor;
	}
	
	public int getAantal() {
		return _aantal;
	}
	
	public void setAantal(int _aantal) {
		this._aantal = _aantal;
	}
	
	public double getStraal() {
		return _straal;
	}
	
	public void setStraal(double _straal) {
		this._straal = _straal;
	}
	
	public double getAfstand() {
		return _afstand;
	}
	
	public void setAfstand(double _afstand) {
		this._afstand = _afstand;
	}	
}
